#ifndef STX_ALGORITHM_COUNT_HPP_
#define STX_ALGORITHM_COUNT_HPP_

#include <stx/algorithm/common.hpp>

namespace stx {

template <class InputIterator, class T>
inline typename std::iterator_traits<InputIterator>::difference_type
count(InputIterator first, InputIterator last, const T& value)
{
    typename std::iterator_traits<InputIterator>::difference_type r(0);
    for (; first != last; ++first) {
        if (*first == value) {
            ++r;
        }
    }
    return r;
}

template<class Container, class T>
inline typename std::iterator_traits<typename Container::iterator>::difference_type
count(Container& c, const T& value)
{
    return stx::count(stx::begin(c), stx::end(c), value);
}

template<class Container, class T>
inline typename std::iterator_traits<typename Container::const_iterator>::difference_type
count(const Container& c, const T& value)
{
    return stx::count(stx::begin(c), stx::end(c), value);
}

template <class InputIterator, class T>
inline typename std::iterator_traits<InputIterator>::difference_type
count(stx::iterator_range<InputIterator> r, const T& value)
{
    return count(stx::begin(r), stx::end(r), value);
}

} // namespace stx

#endif // STX_ALGORITHM_COUNT_HPP_
